<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>车间管理</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" th:href="@{/favicon.ico}">
    <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
    <link th:href="@{/css/font-awesome.css}" rel="stylesheet">
    <link th:href="@{/css/animate.css}" rel="stylesheet">
    <link th:href="@{/css/style.css}" rel="stylesheet">
    <link th:href="@{/self/self-common.css}" rel="stylesheet">

    <link th:href="@{/css/plugins/bootstrap-table/bootstrap-table.min.css}" rel="stylesheet">
    <link th:href="@{/css/plugins/bootstrap-select/bootstrap-select.css}" rel="stylesheet">

    <!-- Sweet Alert -->
    <link th:href="@{/css/plugins/sweetalert/sweetalert.css}" rel="stylesheet">

    <!--zTree css引用-->
    <link th:href="@{/self/zTree/metroStyle.css}" rel="stylesheet"/>
</head>

<body class="gray-bg">

<!--内页左侧布局及树-->
<div class="ui-layout-west">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">工厂</div>
            <div class="box-operation">
                <a id="clickAddShopType" title="新增"><i class="fa fa-plus"></i></a>
                <a id="clickUpdateShopType" title="编辑"><i class="fa fa-edit"></i></a>
                <a id="clickDeleteShopType" title="删除"><i class="fa fa-trash"></i></a>
            </div>
        </div>
        <div class="ui-layout-content">
            <div id="tree" class="ztree"></div>
        </div>
    </div>
</div>
<!--折叠按钮-->
<div class="ui-layout-resizer ui-layout-resizer-open">
    <div class="ui-layout-toggler" title="折叠">
        <span class="ui-content content-open" style="display: block;"><i class="fa fa-caret-left"></i></span>
        <span class="ui-content content-closed" style="display: none;"><i class="fa fa-caret-right"></i></span>
    </div>
</div>
<!--内页左侧布局及树 end-->

<!------------------------------车间类型------------------------------>
<div class="ui-layout-center">
    <div class="wrapper wrapper-content animated fadeInRight">

        <div class="row">
            <div class="col-sm-12 search-card">
                <div class="ibox">
                    <div class="ibox-content">
                        <form class="form-inline">
                            <div class="form-group searchCX">
                                <input id="searchShopName" class="form-control" type="text" placeholder="请输入车间名称"
                                       clearable>
                            </div>
                            <div class="form-group searchCX">
                                <input id="searchShopSn" class="form-control" type="text" placeholder="请输入车间编号"
                                       clearable>
                            </div>
                            <div class="form-group">
                                <button id="btnSearch" class="btn btn-purple" type="button" onclick="querySearch()">
                                    <i class="fa fa-search"></i>
                                    查询
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
            <!--新增车间类型-->
            <div class="modal inmodal fade" id="addShopType">
                <div class="modal-dialog modal-lg">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4 class="modal-title">新增工厂</h4>
                            <button type="button" class="close" data-dismiss="modal">×</button>
                        </div>
                        <div class="modal-body">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">工厂名称：</label>
                                    <div class="col-sm-7">
                                        <input id="addShopTypeName" type="text" name="" class="form-control"
                                               placeholder="请输入工厂名称">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-white btn-close" data-dismiss="modal">取消</button>
                            <button type="button" class="btn btn-purple btn-save" id="btnAddSaveShopType">保存</button>
                        </div>
                    </div>
                </div>
            </div>

            <!--变更车间类型-->
            <div class="modal inmodal fade" id="shopTypeUpdate">
                <div class="modal-dialog modal-lg">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4 class="modal-title">编辑工厂</h4>
                            <button type="button" class="close" data-dismiss="modal">×</button>
                        </div>
                        <div class="modal-body">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">工厂名称：</label>
                                    <div class="col-sm-7">
                                        <input id="updateShopTypeName" type="text" name="" class="form-control"
                                               placeholder="请输入车间名称">
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="modal-footer">
                            <button type="button" class="btn btn-white btn-close" data-dismiss="modal">取消</button>
                            <button type="button" class="btn btn-purple btn-save" id="btnUpdateSaveShopType">保存
                            </button>
                        </div>

                    </div>
                </div>
            </div>

            <!------------------------------车间信息------------------------------>
            <div class="col-sm-12 table-card">
                <div class="ibox ">
                    <div class="ibox-title">
                        <h5>
                            <i class="fa fa-bookmark"></i>
                            车间信息管理
                        </h5>
                    </div>
                    <div class="ibox-content">
                        <div id="toolbar">
                            <form class="form-inline btnOpacity">
                                <div class="btn-group">
                                    <button class="btn btn-purple" type="button" id="btnAddShop">
                                        <i class="fa fa-plus-circle"></i>
                                        新增
                                    </button>
                                </div>
                                <div class="form-group">
                                    <button id="importBtn" class="btn btn-purple" type="button" data-toggle="modal" data-target="#myModal">
                                        <i class="fa fa-upload"></i>
                                        导入
                                    </button>
                                </div>
                                <div class="form-group">
                                    <button id="export" class="btn btn-orange" type="button">
                                        <i class="fa fa-download"></i>
                                        导出
                                    </button>
                                </div>
                                <!--                                <div class="btn-group">-->
                                <!--                                    <button class="btn btn-orange" type="button" id="btnUpdateShop">-->
                                <!--                                        <i class="fa fa-pencil-square-o"></i>-->
                                <!--                                        修改-->
                                <!--                                    </button>-->
                                <!--                                </div>-->
                                <!--                                <div class="btn-group">-->
                                <!--                                    <button class="btn btn-red" type="button" id="btnDeleteShop">-->
                                <!--                                        <i class="fa fa-times"></i>-->
                                <!--                                        删除-->
                                <!--                                    </button>-->
                                <!--                                </div>-->
                            </form>
                        </div>
                        <table id="dataTable" data-mobile-responsive="true"></table>
                    </div>

                </div>
            </div>
        </div>

        <div class="modal inmodal fade" id="addShop">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title">新增车间</h4>

                        <button type="button" class="close" data-dismiss="modal">×</button>
                    </div>
                    <div class="modal-body">

                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">车间编号：</label>
                                <div class="col-sm-7">
                                    <input id="addShopSn" type="text" name="" class="form-control"
                                           placeholder="请输入车间编号">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label">车间名称：</label>
                                <div class="col-sm-7">
                                    <input id="addShopName" type="text" name="" class="form-control"
                                           placeholder="请输入车间名称">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label">车间状态：</label>
                                <div class="col-sm-7">
                                    <select id="addState" class="selectpicker show-tick" title="车间状态">
                                        <option value="0">停用</option>
                                        <option value="1" selected>正常</option>
                                    </select>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label">备注：</label>
                                <div class="col-sm-7">
                                    <textarea class="form-control diff-textarea" id="addRemarks" rows="6"
                                              autocomplete="off" placeholder="请输入备注"></textarea>
                                </div>
                            </div>

                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-white btn-close" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-purple btn-save" id="btnAddSave">保存</button>
                    </div>
                </div>
            </div>
        </div>

        <div class="modal inmodal fade" id="updateShop">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title">编辑车间</h4>

                        <button type="button" class="close" data-dismiss="modal">×</button>
                    </div>
                    <div class="modal-body">

                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">车间编号：</label>
                                <div class="col-sm-7">
                                    <input id="updateShopSn" type="text" name="" class="form-control"
                                           placeholder="请输入车间编号">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label">车间名称：</label>
                                <div class="col-sm-7">
                                    <input id="updateShopName" type="text" name="" class="form-control"
                                           placeholder="请输入车间名称">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label">车间状态：</label>
                                <div class="col-sm-7">
                                    <select id="updateState" class="selectpicker show-tick" title="车间状态">
                                        <option value="0">停用</option>
                                        <option value="1" selected>正常</option>
                                    </select>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label">备注：</label>
                                <div class="col-sm-7">
                                    <textarea class="form-control diff-textarea" id="updateRemarks" rows="6"
                                              autocomplete="off" placeholder="请输入备注"></textarea>
                                </div>
                            </div>

                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-white btn-close" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-purple btn-save" id="btnUpdateSave">保存</button>
                    </div>
                </div>
            </div>
        </div>

        <!--导入模态框-->
        <div class="modal inmodal fade" id="myModal">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title">工单导入</h4>
                        <button type="button" class="close" data-dismiss="modal" onclick="removeImp()">×</button>
                    </div>
                    <div class="modal-body">
                        <div class="col-md-12">
                            <div class="form-group">
                                <div class="import_btn" style="width:100%;text-align:left">
                                    <label for="import" ><span>选择文件</span></label>
                                    <span id="fileName">未上传文件</span>
                                </div>
                                <input type="file" id="import" onchange="loadFile(this.files[0])" name="import" style="width: 220px;opacity:0">
                            </div>
                            <div class="form-group">
                                <a class="downtele" style="text-align:left;" href="#" onclick="downLoadTemp();" ><span style="padding:5px ;font-size:16px;font-weight:200;color:#337ab7">模板下载</span></a>
                            </div>
                        </div>

                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-white btn-close" data-dismiss="modal" onclick="removeImp()">取消</button>
                        <button type="button" class="btn btn-purple btn-save" id="btnSave" onclick="mySubmit()">保存</button>
                    </div>
                </div>
            </div>
        </div>

    </div>


</div>

<!-- 全局js -->
<script th:src="@{/js/jquery.min.js}"></script>
<script th:src="@{/js/bootstrap.min.js}"></script>
<script th:src="@{/js/content.js}"></script>
<script th:src="@{/js/app.js}" type="text/javascript"></script>

<!-- Bootstrap table -->
<script th:src="@{/js/plugins/bootstrap-table/bootstrap-table.min.js}"></script>
<script th:src="@{/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js}"></script>
<script th:src="@{/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js}"></script>
<!--提示框-->
<script th:src="@{/js/plugins/layer/layer.min.js}"></script>
<!--下拉选择框-->
<script th:src="@{/js/plugins/bootstrap-select/bootstrap-select.js}"></script>
<!--日期-->
<script th:src="@{/js/plugins/layer/laydate/laydate.js}"></script>

<!--bootstrap导出-->
<script th:src="@{/js/plugins/bootstrap-table-export/bootstrap-table-export.js}"></script>
<script th:src="@{/js/plugins/bootstrap-table-export/tableExport.js}"></script>
<!--pdf导出 文本乱码问题-->
<script th:src="@{/js/plugins/bootstrap-table-export/pdfmake/pdfmake.min.js}"></script>
<script th:src="@{/js/plugins/bootstrap-table-export/pdfmake/gbsn00lp_fonts.js}"></script>
<!--将表导出为PDF文件-->
<script th:src="@{/js/plugins/bootstrap-table-export/pdfmake/jspdf.min.js}"></script>
<script th:src="@{/js/plugins/bootstrap-table-export/pdfmake/jspdf.plugin.autotable.js}"></script>

<script th:src="@{/js/plugins/sweetalert/sweetalert.min.js}"></script>

<!--zTree js引用-->
<script th:src="@{/self/zTree/jquery.ztree.all.min.js}"></script>
<script th:src="@{/self/zTree/self-zTree.js}"></script>

<script>
    var shopTypeId = 0;
    var shopId = '';

    //查询车间
    function querySearch() {
        $('#dataTable').bootstrapTable('refresh');
    }

    <!--zTree树状图-->
    var settings = {
        view: {
            showIcon: false,
            showLine: false
        },
        data: {
            simpleData: {
                enable: true, //true 、 false 分别表示 使用 、 不使用 简单数据模式
                idKey: "id", //节点数据中保存唯一标识的属性名称
                pIdKey: "pId", //节点数据中保存其父节点唯一标识的属性名称
                rootPId: -1 //用于修正根节点父节点数据，即 pIdKey 指定的属性值
            },
            key: {
                name: "name" //zTree 节点数据保存节点名称的属性名称  默认值："name"
            }
        },
        check: {
            enable: false, //true 、 false 分别表示 显示 、不显示 复选框或单选框
            nocheckInherit: true //当父节点设置 nocheck = true 时，设置子节点是否自动继承 nocheck = true
        },
        callback: {
            onClick: zTreeOnClick,
        }
    };

    //树状按钮点击控制
    function zTreeOnClick(event, treeId, treeNode) {
        shopId = '';
        shopTypeId = treeNode.id;
        if (treeNode.pId == -1) {
            $("#clickAddShopType").attr("disabled", false);
            $("#clickUpdateShopType").attr("disabled", true);
            $("#clickDeleteShopType").attr("disabled", true);
        } else if (treeNode.pId == 0) {
            $("#clickAddShopType").attr("disabled", true);
            $("#clickUpdateShopType").attr("disabled", false);
            $("#clickDeleteShopType").attr("disabled", false);
        }
        $('#dataTable').bootstrapTable('refresh');
        ztreeStyle(event, treeId, treeNode)//改变ztree样式
    }

    //首页树状按钮点击控制
    $(document).ready(function () {
        showShopType();
        $("#clickAddShopType").attr("disabled", true);
        $("#clickUpdateShopType").attr("disabled", true);
        $("#clickDeleteShopType").attr("disabled", true);
        showShopType();

        //展示车间类型
        function showShopType() {
            PostWebApi("getAllShopTypeTree").done(function (data) {
                if (data.code == 0) {
                    var info = data.data;
                    if (info) {
                        zTreeObj = $.fn.zTree.init($("#tree"), settings, info); //初始化树
                        zTreeObj.expandAll(true); //true 节点全部展开、false节点收缩
                    }
                }
            })
        }

        $("#addShopType").on("hidden.bs.modal", function () {
            $("#addShopTypeName").val("");
        });

        //新增车间类型
        var addShopTypeId = 0;
        $("#clickAddShopType").click(function () {
            var treeObj = $.fn.zTree.getZTreeObj("tree");
            var sNodes = treeObj.getSelectedNodes();
            //点击事件：新增车间类型 判断
            // if (sNodes.length < 1) {
            //     layer.msg("请选择标签");
            //     return;
            // }
            var id = sNodes[0].id;
            addShopTypeId = id;
            $("#addShopType").modal('show');
        })

        //保存新增车间类型
        $("#btnAddSaveShopType").click(function () {
            var shopTypeName = $("#addShopTypeName").val();
            if (!shopTypeName) {
                layer.msg("请输入工厂名称")
                return
            }
            PostWebApi("addShopType", {
                shopTypeName: shopTypeName,
                parentId: addShopTypeId,
            }).done(function (data) {
                if (data.code === 0) {
                    layer.msg(data.msg);
                    $("#addShopType").modal('hide');
                    //刷新树结构
                    showShopType()
                    // $('#dataTable').bootstrapTable('refresh');
                } else {
                    layer.msg(data.msg);
                }
            });
        });

        //编辑车间类型
        var updateId = 0;
        $("#clickUpdateShopType").click(function () {
            var treeObj = $.fn.zTree.getZTreeObj("tree");
            var sNodes = treeObj.getSelectedNodes();
            var id = sNodes[0].id;
            updateId = id;
            PostWebApi("getShopTypeById", {
                id: id
            }).done(function (data) {
                if (data.code == 0) {
                    var info = data.data;
                    if (info) {
                        $("#updateShopTypeName").val(info.shopTypeName);
                    }
                    $("#shopTypeUpdate").modal('show');
                }
            })
        })

        //保存编辑车间类型
        $("#btnUpdateSaveShopType").click(function () {
            var shopTypeName = $("#updateShopTypeName").val();
            if (!shopTypeName) {
                layer.msg("请输入车间名称")
                return
            }
            PostWebApi("updateShopType", {
                id: updateId,
                shopTypeName: shopTypeName,
            }).done(function (data) {
                if (data.code === 0) {
                    layer.msg(data.msg);
                    $("#shopTypeUpdate").modal('hide');
                    // 刷新树形结构
                    showShopType()
                } else {
                    layer.msg(data.msg);
                }
            });
        });

        //删除车间类型
        $("#clickDeleteShopType").click(function () {
            var treeObj = $.fn.zTree.getZTreeObj("tree");
            var sNodes = treeObj.getSelectedNodes();
            //点击事件：删除 判断
            // if (sNodes.length < 0) {
            //     layer.msg("请选择标签");
            //     return;
            // }
            var id = sNodes[0].id;
            // var pId = sNodes[0].pId;
            // if (pId == -1) {
            //     layer.msg("顶级标签不可删除");
            //     return;
            // }
            deleteShopType(id);
        })

        //保存删除车间类型
        //弹出提示，是否确认删除，防止用户误操作
        function deleteShopType(id) {
            swal({
                title: "您确定删除该工厂吗",
                //text: "删除后将无法恢复，请谨慎操作！",
                type: "warning",
                showCancelButton: true,
                cancelButtonText: "取消",
                confirmButtonColor: "rgb(85 221 218)",
                confirmButtonText: "确定",
                closeOnConfirm: false
            }, function () {
                swal.close();
                PostWebApi("deleteShopType", {
                    id: id
                }).done(function (data) {
                    if (data.code === 0) {
                        layer.msg('删除成功');
                        // 刷新树形结构
                        showShopType();
                        // 车间类型清空
                        shopTypeId = 0;
                        // 刷新table
                        $('#dataTable').bootstrapTable('refresh');
                    } else {
                        layer.msg(data.msg);
                    }
                });
            })
        }

//---------------------------车间信息----------------------------------

        function queryParams(params) {
            return {
                pageSize: params.pageSize,
                pageNumber: params.pageNumber,

                shopSn: $.trim($("#searchShopSn").val()),
                shopName: $.trim($("#searchShopName").val()),
                shopTypeId: shopTypeId,
            }
        }

        $('#dataTable')
            .bootstrapTable({
                url: baseUrl + "getShopPageList",
                method: "post",
                queryParamsType: "",
                queryParams: queryParams,
                pageNumber: 1, //初始化加载第一页，默认第一页
                pageSize: 10, //每页的记录行数（*）
                striped: false, //是否显示行间隔色
                cache: false, //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                search: false, //是否显示搜索框功能
                pagination: true, //是否分页
                showRefresh: false, //是否显示刷新功能
                showToggle: false,
                showColumns: false,
                // clickToSelect: true, //是否启用点击选中行
                // uniqueId: "indentId", //每一行的唯一标识，一般为主键列
                // idField: "indentId",
                formatSearch: function () {
                    return "车间编号";
                },
                iconSize: 'outline',
                sidePagination: "server", //服务端请求
                showExport: false,//显示导出按钮
                buttonsAlign: "right",  //按钮位置
                exportTypes: ['excel'],  //导出文件类型
                pageList: [10, 20, 30, 'all'],
                exportDataType: "basic",//导出类型 'basic':当前页, 'all', 'selected'.
                toolbar: '#toolbar', //工具按钮用哪个容器
                icons: {
                    refresh: 'glyphicon-repeat',
                    toggle: 'glyphicon-list-alt',
                    columns: 'glyphicon-list',
                    export: 'glyphicon-export'
                },
                exportOptions: {
                    ignoreColumn: [3],
                    // fileName: '车间信息'
                }
                , responseHandler: function (res) {
                    console.log(res)
                    var rows = [];
                    if (res.total !== 0) {
                        rows = res.list;
                    }
                    var result = {
                        rows: rows,
                        total: res.total
                    };
                    return result;
                },
                onEditableSave: function (field, row, oldValue, $ele) {
                    //更新数据到数据库
                },
                columns: [
                    {
                        field: 'shopSn',
                        title: '车间编号',
                        formatter: function (value, row, index) {
                            if (value == null) {
                                return '';
                            } else {
                                return value;
                            }
                        }
                    }, {
                        field: 'shopName',
                        title: '车间名称',
                        formatter: function (value, row, index) {
                            if (value == null) {
                                return '';
                            } else {
                                return value;
                            }
                        }
                    }, {
                        field: 'shopTypeName',
                        title: '工厂',
                        formatter: function (value, row, index) {
                            if (value == null) {
                                return '';
                            } else {
                                return value;
                            }
                        }
                    }, {
                        field: 'createTime',
                        title: '创建时间',
                        formatter: function (value, row, index) {
                            if (value == null) {
                                return '';
                            } else {
                                return value;
                            }
                        }
                    }, {
                        field: 'userName',
                        title: '创建人',
                        formatter: function (value, row, index) {
                            if (value == null) {
                                return '';
                            } else {
                                return value;
                            }
                        }
                    }, {
                        field: 'remarks',
                        title: '备注',
                        formatter: function (value, row, index) {
                            if (value == null) {
                                return '';
                            } else {
                                return value;
                            }
                        }
                    }, {
                        field: 'state',
                        title: '状态',
                        formatter: function (value, row, index) {
                            if (row.state == '1') {
                                return '正常'
                            } else if (row.state == '0') {
                                return '停用';
                            }
                        }
                    }, {
                        field: 'operation',
                        title: '操作',
                        align: 'center',
                        width: '100',
                        formatter: function (value, row, index) {
                            var startBtn = "<button type='button' class = 'btn btngroup btn-xs czIcon icon_edit' onclick='editShop(\"" + row.id + "\")' title='编辑'></button>";
                            var closeBtn = "<button type='button' class = 'btn btngroup btn-xs czIcon icon_close'  onclick='deleteShop(\"" + row.id + "\")' title='删除'></button>";
                            return startBtn + closeBtn;
                        }
                    }],
            });

        $("#addShop").on("hidden.bs.modal", function () {
            $("#addShopSn").val("");
            $("#addShopName").val("");
            $("#addRemarks").val("");
            $("#addState").val("").selectpicker('refresh');
        });

    })

    //新增车间按钮
    $("#btnAddShop").on('click', function () {
        if (shopTypeId == 0) {
            layer.msg("请先选择工厂");
            return
        }
        $('#addShop .modal-header .modal-title').empty().text("新增车间");
        $('#addShop').modal();
    })

    //保存新增车间
    $("#btnAddSave").on('click', function (e) {
        var shopSn = $("#addShopSn").val();
        var shopName = $("#addShopName").val();
        var remarks = $("#addRemarks").val();
        var state = $("#addState").val();

        if (shopTypeId == 0) {
            layer.msg("请选择工厂")
            return
        }
        PostWebApi("addShop", {
            shopSn: shopSn,
            shopName: shopName,
            shopTypeId: shopTypeId,
            remarks: remarks,
            state: state,
        }).done(function (data) {
            if (data.code === 0) {
                $("#addShop").modal('hide');
                $('#dataTable').bootstrapTable('refresh');
            } else {
                layer.msg(data.msg);
            }
        });
    })

    //编辑
    function editShop(editShopId) {
        PostWebApi("getShopById", {
            id: editShopId,
        }).done(function (data) {
            $("#updateShopSn").val(data.shopSn);
            $("#updateShopName").val(data.shopName);
            $("#updateRemarks").val(data.remarks);
            $("#updateState").val(data.state).selectpicker('refresh');
            $('#updateShop .modal-header .modal-title').empty().text("修改车间");
            $('#updateShop').modal();
        });
        shopId = editShopId
    }

    //修改保存
    $("#btnUpdateSave").on('click', function () {
        var shopSn = $("#updateShopSn").val();
        var shopName = $("#updateShopName").val();
        var remarks = $("#updateRemarks").val();
        var state = $("#updateState").val();
        PostWebApi("updateShop", {
            shopSn: shopSn,
            shopName: shopName,
            remarks: remarks,
            state: state,
            id: shopId
        }).done(function (data) {
            if (data.code === 0) {
                $("#updateShop").modal('hide');
                $('#dataTable').bootstrapTable('refresh');
                shopId = '';
            } else {
                layer.msg(data.msg);
            }
        });
    })

    //删除按钮
    function deleteShop(deleteShopId) {
        swal({
            title: "您确定删除该车间吗",
            //text: "删除后将无法恢复，请谨慎操作！",
            type: "warning",
            showCancelButton: true,
            cancelButtonText: "取消",
            confirmButtonColor: "rgb(85 221 218)",
            confirmButtonText: "确定",
            closeOnConfirm: false
        }, function () {
            swal.close();
            PostWebApi("deleteShop", {
                id: deleteShopId
            }).done(function (data) {
                if (data.code === 0) {
                    layer.msg('删除成功');
                    $('#dataTable').bootstrapTable('refresh');
                    shopId = '';
                } else {
                    layer.msg(data.msg);
                }
            });
        })
    }

    //----------------------------EXCEL-------------------------------------
    // 使用tableExport.js导出数据
    $("#export").click(function () {
        $('#dataTable').tableExport(
            {
                type: 'excel',//导出excel
                escape: 'false',
                ignoreColumn: [7],  //忽略某一列的索引
                fileName: '车间信息',  //文件名称设置
                worksheetName: '车间信息',  //表格工作区名称
                tableName: '车间信息',
                excelstyles: ['background-color', 'color', 'font-size', 'font-weight']
            }
        )
    })

    //下载导入模版
    function downLoadTemp(){
        window.location.href =baseUrl + "downShopExcelTemplate?fileName=车间导入模版";
    }

    //移除文件文字
    function removeImp(){
        var file = document.getElementById('import');
        file.value = ''; //虽然file的value不能设为有字符的值，但是可以设置为空值
        //或者
        //file.outerHTML = file.outerHTML; //重新初始化了file的html
        $("#fileName").html('未上传文件');
    }

    //加载文件名
    function loadFile(file){
        $("#fileName").html(file.name);
    }

    //导入excel文件信息
    function mySubmit(){
        var  file = document.getElementById("import").files[0];
        var fileName=$("#fileName").val();
        var preffix = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.lastIndexOf("."));
        var suffix = fileName.substring(fileName.lastIndexOf("."));
        //创建新的表单数据对象
        var formData = new FormData();
        formData.append("file", file);
        formData.append("preffix", preffix);
        formData.append("suffix", suffix);
        $.ajax({
            url: baseUrl +"shopImport",
            type: "POST",
            contentType: false,
            datatype: "text",
            data: formData,
            processData: false, // 告诉jQuery不要去处理发送的数据
            success: function (data) {
                $('#dataTable').bootstrapTable('refresh');
                layer.msg(data.msg)
            }
        });
        removeImp();
        $('#myModal').modal('hide');
        return false;
    }


</script>

</body>

</html>
